<script>
import { bannerSwiper } from '@/api/constant'
import CardCom from './card-com.vue'
export default {
  name: 'HomePage',
  data () {
    return {
      bannerSwiper,
      active: 1,
      activeNode: 1
    }
  },
  methods: {
    instantiateSwiper () {
      const vue = this
      // eslint-disable-next-line
      new Swiper(".swiper", {
        loop: true, // 循环模式选项
        autoplay: {
          delay: 5000,
          disableOnInteraction: false,
          pauseOnMouseEnter: true
        },
        // 如果需要分页器
        pagination: {
          el: '.swiper-pagination',
          clickable: true
        },
        on: {
          slideChangeTransitionEnd () {
            let index
            console.log(this.activeIndex)
            switch (this.activeIndex) {
              case 0:
                index = vue.bannerSwiper.length
                break
              case vue.bannerSwiper.length + 1:
                index = 1
                break
              default:
                index = this.activeIndex
                break
            }
            vue.active = index
          }
        }
      })
    },
    instantiateNodeSwiper () {
      const vue = this
      // eslint-disable-next-line
      new Swiper(".swiper-node", {
        // 如果需要分页器
        pagination: {
          el: '.swiper-pagination',
          clickable: true
        },
        // 如果需要前进后退按钮
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        },
        loop: true, // 循环模式选项
        autoplay: {
          delay: 5000,
          disableOnInteraction: false,
          pauseOnMouseEnter: true
        },
        slidesPerView: 2,
        spaceBetween: (7 / 375) * vue.$width,
        on: {
          slideChangeTransitionEnd () {
            let index = (this.activeIndex - 1) % vue.bannerSwiper.length
            index === 0 && (index = vue.bannerSwiper.length)
            vue.activeNode = index
          }
        }
      })
    }
  },
  components: {
    CardCom
  },
  mounted () {
    this.instantiateSwiper()
    this.instantiateNodeSwiper()
  }
}
</script>

<template>
  <div class="home-page">
    <div class="swiper">
      <div class="swiper-wrapper">
        <div
          class="swiper-slide"
          v-for="item in bannerSwiper"
          :key="item.image"
        >
          <img :src="item.image" alt="" />
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>

      <div class="pager">
        <span class="now">{{ String(active).padStart(2, "0") }}</span>
        <span>/</span>
        <span class="all">{{
          String(bannerSwiper.length).padStart(2, "0")
        }}</span>
      </div>
    </div>

    <div class="about-us">
      <CardCom zn="关于我们" en="ABOUT US">
        <div class="about-content">
          <div class="image">
            <img
              src="http://www.yuhuachina.com/Temp/PC/images/img11.png"
              alt=""
            />
          </div>
          <div class="info">
            <div class="introduction">
              <p>
                “人人成才，德技双馨”我们为每一名学生量身打造培养计划，帮助每一名学生塑造人格、铸就能力，实现华丽的转身。面对高速发展的今天，数字技术、人工智能技术的出现，不断推动产业结构调整、动能的转换。
              </p>
              <p>
                为适应当前的发展趋势，学校设立数字媒体、人工智能开发两个专业方向，培养八大岗位：视觉设计师、C4D工程师、智能产品经理，架构工程师、算力工程师、大模型工程师、计算机神经系统工程师；以实际工作岗位标准为教学目标，以项目贯穿为教学思路，以实习实训结合的教学方式，让每一名学生快速掌握岗位技能
              </p>
            </div>
            <div class="under-more"  @click="$router.push('/about/introduction')">
              <span>了解更多</span>
              <i class="icon">
                <img :src="$url + '/icon/right-primary.png'" alt="" />
              </i>
            </div>
          </div>
        </div>
      </CardCom>
    </div>

    <div class="news" ref="news">
      <CardCom zn="新闻动态" en="News" color="#000">
        <div class="news-content">
          <div class="swiper-node">
            <div class="swiper-wrapper">
              <div
                class="swiper-slide"
                v-for="(item,i) in bannerSwiper"
                :key="item.image"
              >
                <img
                  src="http://www.yuhuachina.com/upload/img/202111/21112919393372ddd8.png"
                  alt=""
                />
                <div class="info">
                  <p>热烈庆祝宇华教育李光宇董事长再次当选全国人大代表</p>
                  <i class="icon icon-right"  @click="$router.push('/news/' + i)">
                    <img :src="$url + '/icon/right-primary.png'" alt="" />
                  </i>
                </div>
              </div>
            </div>
            <!-- 如果需要分页器 -->

            <!-- 如果需要导航按钮 -->
            <div class="swiper-button-prev"></div>
            <div class="swiper-button-next"></div>

            <div class="operate">
              <div class="pager">
                <span class="now">{{
                  String(activeNode).padStart(2, "0")
                }}</span>
                <span>/</span>
                <span class="all">{{
                  String(bannerSwiper.length).padStart(2, "0")
                }}</span>
              </div>
              <div class="swiper-pagination"></div>
            </div>
          </div>
        </div>
      </CardCom>
    </div>

    <div class="other">
      <div class="card">
        <div class="image">
          <img
            src="http://www.yuhuachina.com/Temp/PC/images/img13.png"
            alt=""
          />
        </div>
        <div class="info">
          <div class="en">Development Planning</div>
          <div class="zn">发展规划</div>
          <div class="more icon" @click="$router.push('/about/development')">
            <img :src="$url + '/icon/right-primary.png'" alt="" />
          </div>
        </div>
      </div>
      <div class="card">
        <div class="image">
          <img
            src="http://www.yuhuachina.com/upload/img/202112/21120615474405af5d.jpg"
            alt=""
          />
        </div>
        <div class="info">
          <div class="en">Educational concept</div>
          <div class="zn">教育理念</div>
          <div class="more icon" @click="$router.push('/idea')">
            <img :src="$url + '/icon/right-primary.png'" alt="" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.home-page {
  .swiper {
    height: 820px;
    overflow: hidden;
    position: relative;
    .swiper-wrapper {
      .swiper-slide {
        img {
          display: block;
          width: 100%;
          height: 100%;
        }
      }
    }

    ::v-deep .swiper-pagination {
      position: absolute;
      display: flex;
      width: 1200px;
      bottom: 10%;
      left: 10%;
      z-index: 2;
      .swiper-pagination-bullet {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: #fff;
        opacity: 0.5;
        margin-right: 20px;
        &-active {
          opacity: 1;
        }
      }
    }

    .pager {
      position: absolute;
      display: flex;
      z-index: 2;
      bottom: 10%;
      right: 20%;
      color: #fff;
      font-size: 50px;
      align-items: flex-end;
      line-height: 1;
      .now {
        font-size: 70px;
      }
      .all {
        margin-left: 10px;
      }
    }
  }
  .about-us {
    background-color: #414099;
    .about-content {
      .image {
        border: 20px solid #fff;
        img {
          display: block;
          width: 100%;
        }
      }

      .info {
        margin-top: 50px;
        font-size: 50px;
        line-height: 1.6;
        .introduction {
          color: #fff;
          p {
            text-indent: 2em;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 4;
            -webkit-box-orient: vertical;
            overflow: hidden;
          }
        }
        .under-more {
          display: flex;
          align-items: center;
          margin-top: 80px;
          color: #fff;
          .icon {
            margin-left: 30px;
            font-size: 60px;
            text-align: center;
            line-height: 23px;
            border-radius: 50%;
            background-color: #fff;
            color: #414099;
          }
        }

        .statistics {
          margin-top: 58px;
          display: flex;
          justify-content: space-between;
          img {
            display: block;
            width: 180px;
          }
        }
      }
    }
  }
  .news {
    padding-bottom: 50px;
    background: #fff;

    .swiper-node {
      width: 100%;
      position: relative;
      padding-bottom: 300px;
      .swiper-wrapper {
        width: 100%;
        height: 450px;
        .swiper-slide {
          width: 840px !important;
          > img {
            display: block;
            width: 840px;
          }
          .info {
            padding: 30px;
            display: flex;
            justify-content: space-between;
            p {
              width: 400px;
              line-height: 100px;
              font-size: 50px;
              color: #1f1f1f;
              font-weight: bold;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
            }
            .icon {
              font-size: 50px;
              width: 100px;
              border-radius: 50%;
              text-align: center;
              line-height: 50px;
              background-color: #e8f1fd;
            }
          }
        }
      }

      .swiper-button-prev,
      .swiper-button-next {
        width: 150px;
        height: 150px;
        border-radius: 50%;
        line-height: 300px;
        text-align: center;
        background-color: #414099;
        color: #fff;
        left: auto;
        top: -150px;
        &::after {
          font-size: 60px;
        }
      }

      .swiper-button-prev {
        right: 200px;
      }
      .swiper-button-next {
        right: 0;
      }

      .operate {
        position: absolute;
        bottom: 0;
        display: flex;
        align-items: center;
        .pager {
          display: flex;
          font-size: 50px;
          align-items: flex-end;
          line-height: 1;
          margin-right: 40px;
          .now {
            font-size: 70px;
            color: #414099;
          }
          .all {
            margin-left: 5px;
          }
        }
        ::v-deep .swiper-pagination {
          position: relative;
          display: flex;
          bottom: 0;
          .swiper-pagination-bullet {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: #a0a0a0;
            margin-right: 20px;
            &-active {
              background-color: #414099;
            }
          }
        }
      }
    }
  }
  .other {
    margin: 50px 100px 130px 100px;
    display: flex;
    justify-content: space-between;

    .card {
      width: 780px;
      height: 780px;
      position: relative;
      background-color: #414099;
      overflow: hidden;
      .image {
        height: 100%;
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        opacity: 0.3;
        transition: 0.5s;
        img {
          display: block;
          width: 100%;
          height: 100%;
        }
      }
      .info {
        padding: 50px;
        color: #fff;
        line-height: 1.6;
        .more {
          width: 100px;
          height: 100px;
          margin-top: 205px;
          border-radius: 50%;
          background-color: #fff;
          text-align: center;
          line-height: 100px;
          font-size: 50px;
        }
      }
    }
  }
}
</style>
